﻿using System;
using System.Collections.ObjectModel;
using Micua.iChat.Common;
using Micua.iChat.Models;

namespace Micua.iChat.ViewModels
{
    public class ChatViewModel : ViewModelBase
    {
        public ChatViewModel()
        {

            SendCommand = new Command(p =>
            {
                var model = p as ChatViewModel;

                return model != null && !string.IsNullOrEmpty(model.Input);
            }, p =>
            {
                var model = p as ChatViewModel;
                if (model != null)
                    System.Diagnostics.Debug.WriteLine(model.Input);
            });


            Target = new User
            {
                //Id = 10001,
                Username = "小伙伴",
                Signature = "hello",
            };

            #region RecentMessages
            Messages = new ObservableCollection<Message>
            {
                new Message { FromId = 10000, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10000, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuemayue约吗约吗约吗ma约吗约吗约吗约吗约吗约吗约吗约吗约吗约吗约吗约吗约吗约吗yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!吗？yuema?hello!吗？yuema?hello!吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10000, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？吗？yuema?hello!?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddMonths(-1) },
                new Message { FromId = 10000, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddSeconds(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？吗？yuema?hello!吗？yuema?hello!吗？yuema?hello!?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10000, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10000, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10000, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？yuema?hello!!!!", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
            };
            #endregion
        }
        public User Target { get; set; }
        public ObservableCollection<Message> Messages { get; set; }

        private string input;

        public string Input
        {
            get { return input; }
            set
            {
                input = value;
                SendCommand.OnCanExecuteChanged();
            }
        }

        public Command SendCommand { get; set; }
    }
}
